package com.service.question.application.executor;

import com.huawei.questionnaire.resources.api.SatisfactionApi;
import com.huawei.questionnaire.resources.dto.SaveInfoResp;
import com.huawei.questionnaire.resources.dto.SavePortraits;
import com.huawei.questionnaire.resources.dto.SaveSatisfaction;
import com.service.question.application.api.IQuestionnaireApi;
import com.service.question.application.assembler.QuestionnaireAssembler;
import com.service.question.infra.entity.QuestionnaireResultEntity;
import com.service.question.infra.mapper.QuestionnaireResultMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * @author ：hjl
 * @date ：Created in 2022/03/10 17:07
 * @description：问卷调查入库功能实现
 */
@Service
public class QuestionnaireExe implements IQuestionnaireApi {
    Logger logger = LoggerFactory.getLogger(SatisfactionApi.class);

    @Autowired
    private QuestionnaireResultMapper resultMapper;

    @Autowired
    private QuestionnaireAssembler questionnaireAssembler;

    @Override
    public SaveInfoResp savePortraitsResult(SavePortraits savePortraits) {
        QuestionnaireResultEntity resultEntity = questionnaireAssembler.buildPortraitsResult(savePortraits);
        return new SaveInfoResp().successNum(resultMapper.insertQuestionnaireResult(resultEntity));
    }

    @Override
    public SaveInfoResp saveSatisfactionResult(SaveSatisfaction saveSatisfaction) {
        QuestionnaireResultEntity resultEntity = questionnaireAssembler.buildSatisfactionResult(saveSatisfaction);
        return new SaveInfoResp().successNum(resultMapper.insertQuestionnaireResult(resultEntity));
    }
}
